package com.betterjr.modules.risk.loan.entity;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.betterjr.common.annotation.MetaData;
import com.betterjr.common.entity.BetterjrEntity;
import com.betterjr.common.selectkey.SerialGenerator;
import com.betterjr.modules.risk.loan.data.LoanTransactionRelationConstantCollections;

@Access(AccessType.FIELD)
@Entity
@Table(name = "t_scf_loan_transaction_relation")
public class LoanTransactionRelation implements BetterjrEntity {

    /** 
     * @Fields serialVersionUID : 
     */
    private static final long serialVersionUID = 3941598316103037883L;

    /**
     * 流水号
     */
    @Id
    @Column(name = "ID", columnDefinition = "INTEGER")
    @MetaData(value = "流水号", comments = "流水号")
    private Long id;

    /**
     * 贷款合同编号
     */
    @Column(name = "L_LOAN_ID", columnDefinition = "INTEGER")
    @MetaData(value = "贷款合同编号", comments = "贷款合同编号")
    private Long loanId;

    /**
     * 交易数据表编号
     */
    @Column(name = "C_TRANSACTIONNO", columnDefinition = "VARCHAR")
    @MetaData(value = "交易数据表编号", comments = "交易数据表编号")
    private String transactionNo;

    /**
     * 状态  1 正常  0 作废
     */
    @Column(name = "C_BUSINSTATUS", columnDefinition = "VARCHAR")
    @MetaData(value = "状态  1 正常  0 作废", comments = "状态  1 正常  0 作废")
    private String businStatus;

    /**
     * 合同名称
     */
    @Column(name = "C_LOAN_AGREEMENTNAME", columnDefinition = "VARCHAR")
    @MetaData(value = "合同名称", comments = "合同名称")
    private String elcAggrementName;

    /**
     * 贷款合同号
     */
    @Column(name = "C_LOAN_AGREEMENTNO", columnDefinition = "VARCHAR")
    @MetaData(value = "贷款合同号", comments = "贷款合同号")
    private String loanAggrementNo;

    @Transient
    private LoanTransaction transaction;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getLoanId() {
        return loanId;
    }

    public void setLoanId(Long loanId) {
        this.loanId = loanId;
    }

    public String getTransactionNo() {
        return transactionNo;
    }

    public void setTransactionNo(String transactionNo) {
        this.transactionNo = transactionNo;
    }

    public String getBusinStatus() {
        return businStatus;
    }

    public void setBusinStatus(String businStatus) {
        this.businStatus = businStatus;
    }

    public String getElcAggrementName() {
        return elcAggrementName;
    }

    public void setElcAggrementName(String elcAggrementName) {
        this.elcAggrementName = elcAggrementName;
    }

    public String getLoanAggrementNo() {
        return loanAggrementNo;
    }

    public void setLoanAggrementNo(String loanAggrementNo) {
        this.loanAggrementNo = loanAggrementNo;
    }

    public LoanTransaction getTransaction() {
        return transaction;
    }

    public void setTransaction(LoanTransaction transaction) {
        this.transaction = transaction;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((businStatus == null) ? 0 : businStatus.hashCode());
        result = prime * result + ((elcAggrementName == null) ? 0 : elcAggrementName.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((loanAggrementNo == null) ? 0 : loanAggrementNo.hashCode());
        result = prime * result + ((loanId == null) ? 0 : loanId.hashCode());
        result = prime * result + ((transactionNo == null) ? 0 : transactionNo.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof LoanTransactionRelation)) {
            return false;
        }
        LoanTransactionRelation other = (LoanTransactionRelation) obj;
        if (businStatus == null) {
            if (other.businStatus != null) {
                return false;
            }
        } else if (!businStatus.equals(other.businStatus)) {
            return false;
        }
        if (elcAggrementName == null) {
            if (other.elcAggrementName != null) {
                return false;
            }
        } else if (!elcAggrementName.equals(other.elcAggrementName)) {
            return false;
        }
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (loanAggrementNo == null) {
            if (other.loanAggrementNo != null) {
                return false;
            }
        } else if (!loanAggrementNo.equals(other.loanAggrementNo)) {
            return false;
        }
        if (loanId == null) {
            if (other.loanId != null) {
                return false;
            }
        } else if (!loanId.equals(other.loanId)) {
            return false;
        }
        if (transactionNo == null) {
            if (other.transactionNo != null) {
                return false;
            }
        } else if (!transactionNo.equals(other.transactionNo)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "LoanTransactionRelation [id=" + id + ", loanId=" + loanId + ", transactionNo=" + transactionNo
                + ", businStatus=" + businStatus + ", elcAggrementName=" + elcAggrementName + ", loanAggrementNo="
                + loanAggrementNo + "]";
    }

    public void saveAddInitValue() {

        this.setId(SerialGenerator.getLongValue("LoanTransactionRelation.id"));

        this.setBusinStatus(LoanTransactionRelationConstantCollections.RELATIONS_BUSINSTATUS_OK);

    }

}
